#!/usr/bin/env python
#coding=utf-8
'''
Created on Aug 15, 2010
@author: lxd
'''
import sys
sys.path.append('..')
from common.web import Web
import json
web = Web()

def parseArea(parentId):
    url = 'http://www.yy365.com/reg!findArea.do?parentId=%s' % parentId
    f = web.fetchData('', url)
    data = f.read()
    jsn = json.loads(data)
    return jsn['result']

country_list = []
provinces = parseArea(0)
for province in provinces:
    cities = parseArea(province['id'])
    for city in cities:
        countries = parseArea(city['id'])
        for country in countries:
            country_list.append(country)

from common.tools import Tools
import os
country_file = os.path.join(Tools.getFatherDir(), 'db', 'country')
Tools.saveData(country_file, country_list) 


    


